<?php

/**
 * 前台基类
 * Class CommonController
 * @author 龙哥<admin@lgzyw.com>
 */
abstract class CommonController extends Controller
{
    //缓存目录
    protected $cacheDir;
    //风格目录
    protected $VIEW_DIR;
    protected $domain;
    function __construct()
    {

         $this->domain = M('bangding')->where(array('domain'=>$_SERVER['HTTP_HOST']))->find();

        cookie('domain',$this->domain);
        if(!$this->domain){
            if(ismobile())
            {
               define('__TEMPLATE__', 'Template/' . C('MOBILE_STYLE'));
               $this->VIEW_DIR = 'Template/' . C('MOBILE_STYLE') . '/';

            }else{define('__TEMPLATE__', 'Template/' . C('WEB_STYLE'));
             $this->VIEW_DIR = 'Template/' . C('WEB_STYLE') . '/';}
        }else{

            if(cookie('mima')=='baidu'){
                if(ismobile())
                {
                    $nexturl = $this->domain['wapurl'];
                }else{
                    $nexturl = $this->domain['nexturl'];
                }
                
                header("Location:".$nexturl);die;


            }else{
                if(ismobile())
                {

                    define('__TEMPLATE__', 'Template/' . $this->domain['wapstyle']);
                    $this->VIEW_DIR = 'Template/' . $this->domain['wapstyle'] . '/';

                } else {
                   
                    define('__TEMPLATE__', 'Template/' . $this->domain['pcstyle']);
                    $this->VIEW_DIR = 'Template/' . $this->domain['pcstyle'] . '/';
                }

            }
            
        }

         
        
        parent::__construct();
     
      
    }

    /**
     * 404页面
     */
    protected function _404()
    {
        set_http_state(404);
        $this->display('Template/system/404');
        exit;
    }

    /**
     * 验证网站关闭
     */
    protected function CheckWebClose(){
        if (!IS_ADMIN && !C("WEB_OPEN")) {
            $this->display('Template/system/web_close');
            exit;
        }
    }
}